
TYPE MyStruct:
    STRUCT
        field1 : BOOL :=1;
        field2 : INT  :=555 ;
    END_STRUCT
END_TYPE




VAR_GLOBAL
	
	a : MyStruct;
    b : MyStruct;
	g_ret : DINT := 111;
	
	 
END_VAR




FUNCTION ADD1 : INT

	VAR_INPUT
    value1 : INT;
    value2 : INT;
	END_VAR
	
	ADD1 := value1 + value2;
	
	 
END_FUNCTION

FUNCTION ADD2 : INT
    VAR
        di1 : DINT;
        x1 : INT := 200;
        x2 : INT := 20;
    END_VAR
        ADD2 := (10*x2) + 50 + 30 + x1;
END_FUNCTION



FUNCTION REDUCE1 : INT

	VAR_INPUT
    value1 : INT;
    value2 : INT;
	END_VAR
	
	VAR
	sum : INT;
	END_VAR
	(*sum := 50;*)
	REDUCE1 := value1 - value2;
	 
END_FUNCTION


PROGRAM pro_reference_call_struct
	VAR
        
        
        ref_a : REF_TO MyStruct; (* REF_TO *)
        ref_b : REF_TO MyStruct;     (* REF_TO *)
        p_a : POINTER TO MyStruct;
        p_b : POINTER TO MyStruct; 
        
    END_VAR

	 a.field1 := 1; 
	 a.field2 := 0;
     b.field1 := FALSE; 
	 b.field2 := 0;
	
	
END_PROGRAM	




FUNCTION main : DINT//要dint返回才正确
	VAR
	//st可以变量可以同类型同名，使用的时候按照后声明的一个来
	//a : MyStruct;
    //b : MyStruct;
		
	ret : SINT := 0;
    res : INT := 0;
	i1 : DINT := 2#101010;
	i2 : DINT := 8#52;
	i3 : DINT := 16#2A;
	li1 : LINT := 0;
	usi1 : USINT := 0;
	ui1 : UINT := 0;
	udi1 : UDINT := 0;
	uli1 : ULINT := 0; 
	b1 : BOOL := 0;
	b2 : BOOL := false;
	//b3 : BYTE := "1231"; b4 : BYTE := 11asd; //不能这么定义
	b5 : BYTE := 112;
		
	D1 : WORD := "21";
	D2 : DWORD := 2;
	D3 : LWORD := AA;	
	D4 : WORD := 1213;
	D5 : DWORD := 213;
	D6 : LWORD := 00;
		
	r1 : REAL := 0;
	lr1 : LREAL := 110;

	//cc : CHAR := "Hello World";//这样定义报错  "Cannot cast from WSTRING to STRING",
	//ss3 : STRING := "123";  //这样定义报错  "Cannot cast from WSTRING to STRING",
	//wsA3 : WCHAR := 'Hello '; //这样定义报错 "Cannot cast from STRING to WCHAR"
	
	
	cc2 : CHAR := 'HelloWorld';
	s3 : STRING := 'Hello World';
	s3 : STRING := 'Hello World21';
	wA3 : WCHAR := "Hello World";
	
	s4 : STRING[55] := 'Foo Baz';
	s5 : STRING := 'Foo 22Baz';
	ws3 : WSTRING := "Hello World";
	
	d1 : TIME := T#25s;
	
	d2 : DATE := DATE#2021-05-02;
	
	d3 : DATE := DATE#2011-12-24;
	
	d4 : DATE := D#2000-1-1;
	
	d5 : DATE_AND_TIME := DATE_AND_TIME#2021-05-02-14:20:10.25;
	
	d6 : DATE_AND_TIME := DATE_AND_TIME#2011-12-24-00:00:1;
	d7 : DATE_AND_TIME := DT#1999-12-31-23:59:59.999;
	
	t1 : TIME_OF_DAY := TIME_OF_DAY#14:20:10.25;
	t2 : TIME_OF_DAY := TIME_OF_DAY#0:00:1;
	t3 : TIME_OF_DAY := TOD#23:59:59.999;
	t4 : TIME := TIME#2d4h6m8s10ms;
	t5 : TIME := T#2d4.2h;
	t6 : TIME := T#-10s4ms16ns;
	t7 : TIME;
	
	int_array : ARRAY[0..4] OF INT;
	int_array2 : ARRAY[0..2, 0..2, 0..2] OF INT := [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26];
	bArray2 : ARRAY[0..7] OF BOOL := [8(FALSE)];
	
	END_VAR
	
	bArray2[7] := TRUE;
    bArray2[6] := FALSE;
    bArray2[5] := TRUE;
	int_array[0] := 0 + 10;
	
	main := 1;
	
	
	res := ADD1(3,1);
	IF (res <> 4) THEN
		main := 11;
	END_IF
	res	:= REDUCE1(3,1);
	IF (res <> 2) THEN
		main := 2;
	END_IF
	t7  := d1 + 10;// "Cannot generate String-Literal for type TIME",
	IF t7 <> 25000000010 THEN
		main := 3;
	END_IF
	//pro_reference_call_struct();
	if a.field2 <> 555 then
		main := 4;
	END_IF
		
END_FUNCTION
